package com.ylbh.modules.freight.controller;

import java.util.Arrays;
import java.util.Map;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.utils.*;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ylbh.modules.freight.entity.ShoppingFreight;
import com.ylbh.modules.freight.service.ShoppingFreightService;


/**
 * 商城运费模板
 *
 * @author czx
 * @date 2019-12-16 09:52:17
 */
@RestController
@RequestMapping("freight")
public class ShoppingFreightController {
    @Autowired
    private ShoppingFreightService shoppingFreightService;

    @ApiOperation("运费模板列表")
    @GetMapping("/queryFreightList")
    @RequiresPermissions("freight:queryFreightList")
    public CommonResult queryFreightList(PageDTO pageDTO){
        PageUtils page = shoppingFreightService.queryFreightList(pageDTO);
        return Ref.ok(page);
    }

    @ApiOperation("运费详情信息")
    @GetMapping("/getFreightDetailsInfoId/{freightId}")
    @RequiresPermissions("freight:getFreightDetailsInfoId")
    public CommonResult getFreightDetailsInfoId(@PathVariable("freightId") Long freightId){
		ShoppingFreight shoppingFreight = shoppingFreightService.getById(freightId);
        return Ref.ok(shoppingFreight);
    }

    @SysLog("修改运费信息")
    @ApiOperation("修改运费信息")
    @PostMapping("/modifyFreightById")
    @RequiresPermissions("freight:modifyFreightById")
    public CommonResult modifyFreightById(@RequestBody ShoppingFreight shoppingFreight){
		shoppingFreightService.modifyFreightById(shoppingFreight);
        return Ref.ok();
    }

    @SysLog("新增运费模板")
    @ApiOperation("新增运费模板")
    @PostMapping("/addFreight")
    @RequiresPermissions("freight:addFreight")
    public CommonResult addFreight(@RequestBody ShoppingFreight shoppingFreight){
		shoppingFreightService.addFreight(shoppingFreight);
        return Ref.ok();
    }

    @SysLog("删除运费模板")
    @ApiOperation("删除运费模板")
    @PostMapping("/removeFreightById")
    @RequiresPermissions("freight:removeFreightById")
    public CommonResult removeFreightById(@RequestBody Long[] freightIds){
        String s = shoppingFreightService.removeFreightById(Arrays.asList(freightIds));
        if (s.equals("成功")) {
            return Ref.ok();
        } else {
            return Ref.error(s);
        }
    }

    @SysLog("修改启用状态")
    @ApiOperation("修改启用状态")
    @PostMapping("modifyIsEnableById/{type}/{id}")
    public CommonResult modifyIsEnableById(@PathVariable Integer type, @PathVariable Integer id) {
        shoppingFreightService.modifyIsEnableById(type, id);
        return Ref.ok();
    }

    @ApiOperation("获取启用状态运费模板")
    @GetMapping("/queryEnableFreightList")
    public CommonResult queryEnableFreightList(PageDTO pageDTO){
        PageUtils page = shoppingFreightService.queryEnableFreightList(pageDTO);
        return Ref.ok(page);
    }

}
